//
//  QibiaoTableViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/28.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "QibiaoTableViewController.h"
#import "NoramlCellMode.h"
#import "NoramlTableViewCell.h"
#import "MyWinTableViewCell.h"
#import "WinDetaiHeaderTableViewCell.h"
#import "PriceTableViewCell.h"
#import "BaojiaTitleTableViewCell.h"
#import "XQModel.h"
#import "WinHeaderMode.h"
#import "WinPriceModel.h"
#import "PeizhiMode.h"
#import "PeiZhiTableViewCell.h"
#import "HuiYingTableViewController.h"

@interface QibiaoTableViewController ()
@property (nonatomic,strong) NSMutableArray *sectionArray;
@end

@implementation QibiaoTableViewController

+(instancetype)viewController{
    QibiaoTableViewController *qbtvc=[[QibiaoTableViewController alloc]initWithStyle:UITableViewStyleGrouped];
    return qbtvc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    self.tableView.backgroundColor=bgGarycolor;
    self.tableView.contentInset=UIEdgeInsetsMake(0, 0, 64, 0);
    [self setupdata];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)setupdata{
    WinHeaderMode *header=[[WinHeaderMode alloc]init];
    header.rowheight=87;
    [self.sectionArray addObject:@[header]];
    WinPriceModel *price=[[WinPriceModel alloc]init];
    price.rowheight=80;
    NoramlCellMode *cheyuan=[[NoramlCellMode alloc]init];
    cheyuan.title=@"车源";
    cheyuan.detail=@"加版";
    NoramlCellMode *color=[[NoramlCellMode alloc]init];
    color.title=@"颜色";
    color.detail=@"黑/加白";
    NoramlCellMode *kuning=[[NoramlCellMode alloc]init];
    kuning.title=@"库龄";
    kuning.detail=@"3个月";
    NoramlCellMode *paifang=[[NoramlCellMode alloc]init];
    paifang.title=@"排放要求";
    paifang.detail=@"国四";
    
    NoramlCellMode *shangpai=[[NoramlCellMode alloc]init];
    shangpai.title=@"上牌地点";
    shangpai.detail=@"深圳";
    NoramlCellMode *jiaohuo=[[NoramlCellMode alloc]init];
    jiaohuo.title=@"交货日期";
    jiaohuo.detail=@"3天";
    NoramlCellMode *didian=[[NoramlCellMode alloc]init];
    didian.title=@"交货地点";
    didian.detail=@"不限";
    NoramlCellMode *fangshi=[[NoramlCellMode alloc]init];
    fangshi.title=@"交车方式";
    fangshi.detail=@"卖家发车";
    PeizhiMode *pezhi=[[PeizhiMode alloc]init];
    pezhi.title=@"配置";
    pezhi.longdetail=@"黑甲4815HSE,豪华大包的经济的健康觉得开始的骄傲就卡死的骄傲是觉得卡就是的空间打开阿卡时间的快捷按键的时刻阿斯顿快捷按键快速的解决啊大姐啊看见大家";
    [self.sectionArray addObject:@[price,cheyuan,color,kuning,paifang,shangpai,jiaohuo,didian,fangshi,pezhi]];
    
    XQModel *mode=[[XQModel alloc]init];
    mode.rowheight=56;
    [self.sectionArray addObject:@[mode]];
    mode.block=^{
        HuiYingTableViewController *hyvc=[HuiYingTableViewController viewController];
        [self.navigationController pushViewController:hyvc animated:YES];
    };
}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0.1;
    }else{
        return 8;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 8;
}
-(NSMutableArray *)sectionArray{
    if ( _sectionArray==nil) {
        _sectionArray=[NSMutableArray array];
    }
    return  _sectionArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return self.sectionArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    NSArray *array=self.sectionArray[section];
    return array.count;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.sectionArray[indexPath.section];
    NoramlCellMode *mode=array[indexPath.row];
    if (mode.block) {
        mode.block();
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *array=self.sectionArray[indexPath.section];
    NoramlCellMode *mode=array[indexPath.row];
    if ([mode isKindOfClass:[WinHeaderMode class]]) {
        WinDetaiHeaderTableViewCell *cell=[WinDetaiHeaderTableViewCell cellWithTableView:tableView];
        return cell;
    }else if([mode isKindOfClass:[WinPriceModel class]]){
        PriceTableViewCell *cell=[PriceTableViewCell cellWithTableView:tableView];
        return cell;
    }else if([mode isKindOfClass:[XQModel class]]){
        BaojiaTitleTableViewCell *cell=[BaojiaTitleTableViewCell cellWithTableView:tableView];
        return cell;
    }else if([mode isKindOfClass:[PeizhiMode class]]){
        PeizhiMode *peizhi=mode;
        PeiZhiTableViewCell *cell=[PeiZhiTableViewCell cell];
        cell.detailtext.text=peizhi.longdetail;
        return cell;
    }else{
        NoramlTableViewCell *cell=[NoramlTableViewCell cellWithTableView:tableView];
        cell.textLabel.text=mode.title;
        cell.detailTextLabel.text=mode.detail;
        return cell;
    }
   
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.sectionArray[indexPath.section];
    NoramlCellMode *mode=array[indexPath.row];
    if (mode.rowheight) {
        return mode.rowheight;
    }else{
        return 36;
    }
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
